package  com.fengke.cn.yejian11.adapter;
import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.fengke.cn.yejian11.R;
import com.fengke.cn.yejian11.activity.ClubInfoActivity;
import com.fengke.cn.yejian11.javabean.ClubList;

import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Administrator on 2017/9/25 0025.
 */

public class ClubListAdapter extends RecyclerView.Adapter {
    private List<ClubList> clubLists;
    private Context context;
    private LayoutInflater layoutInflater;

    public ClubListAdapter(Context context,List<ClubList> clubLists){
        this.context=context;//保存上下文
        this.clubLists=clubLists;//显示内容
    }



    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View itemView=LayoutInflater.from(context).inflate(R.layout.item_clublist,viewGroup,false);
        ClubListViewHolder holder=new ClubListViewHolder(itemView);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {

        ClubListViewHolder clubListViewHolder= (ClubListViewHolder) viewHolder;
        ClubList club=clubLists.get(position);
        final String address="http://172.24.10.175/workout/Uploads/"+club.getThumb();
        String name=club.getClub_name();
        final String Club_ID=club.getId();
        final String Club_Name=club.getClub_name();

        clubListViewHolder.club_name.setText(name);
        if (!club.getThumb().equals("")){
            Picasso.with(context).load(address).into(clubListViewHolder.club_pic);
        }else {
            Picasso.with(context).load(R.drawable.dog).into(clubListViewHolder.club_pic);
        }

        //////////////////////////点击事件
        clubListViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //启动新的Activity-店铺详情(菜品列表)
                Intent intent = new Intent(context, ClubInfoActivity.class);
                intent.putExtra("Club_Id",Club_ID);
                intent.putExtra("Club_Name",Club_Name);
                intent.putExtra("Club_Pic",address);
                context.startActivity(intent);//启动Activity的时候要注意，加context
            }
        });

    }

    @Override
    public int getItemCount() {
        return clubLists.size();
    }

    public class ClubListViewHolder extends RecyclerView.ViewHolder {

        public ImageView club_pic;
        public TextView club_name;
        public View itemView;
        public ClubListViewHolder(View itemView) {
            super(itemView);
            this.itemView=itemView;
            club_pic= (ImageView) itemView.findViewById(R.id.club_pic);
            club_name= (TextView) itemView.findViewById(R.id.club_name);
        }
    }
}
